<?php
include_once("../conn.php");
$sql = "SELECT * FROM `articles`";
// 预处理sql语句
$stmt = $conn->prepare($sql);
// 执行sql语句
$stmt->execute();
// 获取所有文章
$articles = $stmt->fetchAll();

?>


<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
    <meta name="generator" content="Hugo 0.88.1">
    <title>后台管理</title>

    <link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/dashboard/">

    
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet">

<meta name="theme-color" content="#7952b3">


    <style>
      .bd-placeholder-img {
        font-size: 1.125rem;
        text-anchor: middle;
        -webkit-user-select: none;
        -moz-user-select: none;
        user-select: none;
      }

      @media (min-width: 768px) {
        .bd-placeholder-img-lg {
          font-size: 3.5rem;
        }
      }
    </style>

    
    <!-- Custom styles for this template -->
    <link href="../admin/css/dashboard.css" rel="stylesheet">
  </head>
  <body>
    
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
  <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">东阳吴彦祖的博客</a>
  <button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
  <div class="navbar-nav">
    <div class="nav-item text-nowrap">
      <a class="nav-link px-3" href="../logout.php">退出</a>
    </div>
  </div>
</header>

<div class="container-fluid">
  <div class="row">
    <nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
      <div class="position-sticky pt-3">
        <ul class="nav flex-column">
          <li class="nav-item">
            <a class="nav-link active" aria-current="page" href="/admin/">
              <span data-feather="home"></span>
              后台首页
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="./list.php">
              <span data-feather="file"></span>
              文章列表
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="./add.php">
              <span data-feather="file"></span>
              添加文章
            </a>
          </li>
        </ul>
      </div>
    </nav>

    <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
	<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
	        <h1 class="h2">文章列表</h1>
	</div>
	<table class="table table-hover align-middle">
	  <thead>
	    <tr>
	      <th scope="col">#</th>
	      <th scope="col">标题</th>
	      <th scope="col">创建时间</th>
	      <th scope="col">操作</th>
	    </tr>
	  </thead>
	  <tbody>
		  <?php
		  foreach($articles as $article) {
		  ?>
	    <tr>
	      <th scope="row"><?=$article['id']?></th>
	      <td><a href="/blog.php?id=<?=$article['id']?>"><?=$article['title']?></a></td>
	      <td><?=$article['ctime']?></td>
	      <td>
        
        <a class="btn btn-warning btn-sm" href="./edit.php?id=<?=$article['id']?>">编辑</a>
        <a class="btn btn-danger btn-sm" href="./del.php?id=<?=$article['id']?>" onclick="return confirm('是否确认删除？')">删除</a>

        </td>
	    </tr>
		<?php
		} 
		?>
	    
	  </tbody>
	</table>
    </main>
  </div>
</div>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/js/bootstrap.bundle.min.js"></script>
    <script src="../admin/js/dashboard.js"></script>
  </body>
</html>
